$(document).ready(function() {

    var VAL = {
        NORMAL : "0000000",
        T_FBPBISOPE : "FBPBISOPE",
        T_FDPAPLYWO : "FDPAPLYWO",
        T_FPPWHSOPE : "FPPWHSOPE",
        T_FIPINQSHT : "FIPINQSHT",
        T_FSPBOXHLD : "FSPBOXHLD",
        T_FBPLSTDAT : "FBPBISDAT",
        EVT_USER :$("#userId").text(),
        DISABLED_ATTR : {
            'disabled' : true
        },
        ENABLED_ATTR : {
            'disabled' : false
        }
    };
    
	var globalBean = {
		opeObjs : {},
		getOpeDsc : function(opeID, opeVer) {
			var i, oary;
			for (i = 0; i < this.opeObjs.length; i++) {
				oary = this.opeObjs[i];
				if (typeof (opeVer) === "undefined") {
					if (opeID == oary.ope_id) {
						return oary.ope_dsc;
					}
				} else {
					if (opeID == oary.ope_id && opeVer == oary.ope_ver) {
						return oary.ope_dsc;
					}
				}
			}
		}
	};
	
	var domObj = {
        $prdseqIdFk : $("#prdseqIdFk"),
        $woIdFk     : $("#woIdFk"),
        $opeIdFk     : $("#opeIdFk"),

		$prdIdSpan	: $("#prdIdSpan"),
		$woIdSpan    : $("#woIdSpan"),
		$mdlIdSpan   : $("#mdlIdSpan"),
		$prdStatSpan : $("#prdStatSpan"),
		$pathSpan    : $("#pathSpan"),
		$pathVerSpan : $("#pathVerSpan"),
		$opeDscSpan  : $("#opeDscSpan"),
		$opeNoSpan   : $("#opeNoSpan"),
		$opeIdSpan   : $("#opeIdSpan"),
		$opeVerSpan  : $("#opeVerSpan"),
		$porcIdSpan  : $("#porcIdSpan"),
        $shtOpeMsg : $("#shtOpeMsg"),
        
        buttons : {
            $query_btn : $("#query_btn"),
            $selectReason_btn : $("#selectReason_btn"),
            $hold_btn   : $("#hold_btn"),
            $release_btn   : $("#release_btn"),
            $upload_btn : $("#upload_btn"),
            $select_file : $("#select_file")
        },
        grids : {
            $reasonListGrd : $("#ReasonListGrd"),
            $reasonListDiv : $("#reasonListDiv"),
            $reasonListPg  : $("#reasonListPg"),

            $glassListGrd : $("#glassListGrd"),
            $glassListDiv : $("#glassListDiv"),
            $glassListPg  : $("#glassListPg"),

            $glassHoldListGrd : $("#glassHoldListGrd"),
            $glassHoldListDiv : $("#glassHoldListDiv"),
            $glassHoldListPg  : $("#glassHoldListPg"),

            $cstHoldListGrd : $("#cstHoldListGrd"),
            $cstHoldListDiv : $("#cstHoldListDiv"),
            $cstHoldListPg  : $("#cstHoldListPg"),

        },
        dialogs : {
            $addReasonDialog : $("#addReasonDialog"),
            $remarkDialog    : $("#remarkDialog"),

            $deptId : $("#deptId"),
            $modalReasonListDiv : $("#modalReasonListDiv"),
            $modalReasonListGrd : $("#modalReasonListGrd"),
            $modalReasonListPg : $("#modalReasonListPg"),

            $ReasonListDiv : $("#ReasonListDiv"),
            $ReasonListGrd : $("#ReasonListGrd"),
            $ReasonListPg : $("#ReasonListPg"),

            // 对话框的确认按钮
            $reasonDialog_sureBtn : $("#reasonDialog_sureBtn"),
            $remarkDialog_sureBtn : $("#remarkDialog_sureBtn")
        }
	};
    var initSelectFnc = {
        iniWoIdSel :function(){
            var inObj = {
                trx_id : VAL.T_FDPAPLYWO,
                action_flg : "Q",
                iary : []
            };
            var outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
                var oaryA = outObj.oary;
                oaryA.sort(compare);
                SelectDom.addSelectArr(domObj.$woIdFk, oaryA, "wo_id","wo_id","",true);
            }
        },
        iniOpeIdSel:function(){
            var inObj = {
                trx_id : VAL.T_FBPBISOPE,
                action_flg : "L"
            };
            var outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
                var oaryA = outObj.oary;
                oaryA.sort(compare);
                SelectDom.addSelectArr_(domObj.$opeIdFk, oaryA, "ope_id","ope_id","ope_dsc",true);
            }
        },
    }
    var btnFunc = {
        //初始化保留信息
        iniCstHold : function (prdSeqId) {
            $("#cstHoldListGrd").jqGrid('clearGridData');
            var inObjs = {
                trx_id : VAL.T_FSPBOXHLD,
                action_flg : "Q",
                prd_seq_id : prdSeqId
            };
            var outObjs = comTrxSubSendPostJson(inObjs);
            if (outObjs.rtn_code === VAL.NORMAL) {
                if (outObjs.tbl_cnt > 0) {
                    setGridInfo(outObjs.oary, "#cstHoldListGrd");
                }
            }
        },
        //单片玻璃查询
        queryPrdFunc : function() {
            var prdSeqId = $.trim(domObj.$prdseqIdFk.val());// 玻璃id
            var inObj = {
                trx_id : VAL.T_FIPINQSHT,
                action_flg : "M",
                prd_seq_id : prdSeqId
            };
            var  outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code === VAL.NORMAL) {
                if(outObj.oary2.length>0){
                    var oary = outObj.oary2[0];
                    if(oary.prd_stat =="WAIT"){
                        var data =  domObj.grids.$glassListGrd.jqGrid("getRowData");
                        if(data.length>0){//列表中有数据
                            for(var i=0; i<data.length;i++){
                                if(oary.prd_seq_id==data[i].prd_seq_id){
                                    showErrorDialog("", "该屏体信息已存在待保留列表中");
                                    return false;
                                }
                            }
                            var newRowId = getGridNewRowID("#glassListGrd");
                            domObj.grids.$glassListGrd.jqGrid("addRowData", newRowId, oary);
                            domObj.$prdseqIdFk.val("");
                        }else{//列表中没有数据，直接添加一条数据
                            var newRowId = getGridNewRowID("#glassListGrd");
                            domObj.grids.$glassListGrd.jqGrid("addRowData", newRowId, oary);
                            domObj.$prdseqIdFk.val("");
                        }
                    }else if(oary.prd_stat =="HOLD"){
                        var data =  domObj.grids.$glassHoldListGrd.jqGrid("getRowData");
                        if(data.length>0){//列表中有数据
                            for(var i=0; i<data.length;i++){
                                if(oary.prd_seq_id==data[i].prd_seq_id){
                                    showErrorDialog("", "该屏体信息已存在保留列表中");
                                    return false;
                                }
                            }
                            var newRowId = getGridNewRowID("#glassListGrd");
                            domObj.grids.$glassHoldListGrd.jqGrid("addRowData", newRowId, oary);
                            domObj.$prdseqIdFk.val("");
                        }else{//列表中没有数据，直接添加一条数据
                            var newRowId = getGridNewRowID("#glassListGrd");
                            domObj.grids.$glassHoldListGrd.jqGrid("addRowData", newRowId, oary);
                            domObj.$prdseqIdFk.val("");
                        }
                    } else{
                        showErrorDialog("", "["+prdSeqId+"]屏体状态为["+oary.prd_stat+"]");
                        return false;
                    }
                }
            }
        },
        //工单站点玻璃查询
        queryBtnfunc : function() {
            clearDataAction();
            var inObj,outObjs;
            var woIdFk = $.trim(domObj.$woIdFk.val());
            var opeIdFk =$.trim(domObj.$opeIdFk.val());
            inObj = {
                trx_id     : VAL.T_FIPINQSHT,
                action_flg : "M",
                wo_id      : woIdFk,
                ope_id     : opeIdFk
            };
            outObjs = comTrxSubSendPostJson(inObj);
            if (outObjs.rtn_code === VAL.NORMAL) {
                // 初始化玻璃信息
                var orayA =[], orayB=[];
                for(var i=0;i<outObjs.oary2.length;i++){
                    if(outObjs.oary2[i].prd_stat=="WAIT" ){
                        orayA.push(outObjs.oary2[i]);
                    }else if(outObjs.oary2[i].prd_stat=="HOLD"){
                        orayB.push(outObjs.oary2[i]);
                    }
                }
                setGridInfo(orayA, "#glassListGrd");
                setGridInfo(orayB, "#glassHoldListGrd");
            }
        },
        selectReasonBtnfunc : function() {
            var ids = domObj.grids.$glassListGrd.jqGrid('getGridParam','selarrrow');
            if(ids.length <= 0){
                showErrorDialog("","请选择需要保留的玻璃！")
                return false;
            }
            domObj.dialogs.$modalReasonListGrd
                .jqGrid("clearGridData");
            // 原因代码对话框的模型
            domObj.dialogs.$addReasonDialog.modal({
                backdrop : true,
                keyboard :true,
                show : false
            });
            domObj.dialogs.$addReasonDialog.modal("show");
            comAddValueByDataCateFnc("#deptId","DEPT","data_ext","data_desc",true);
            // 加载原因代码
                var deptId, iary, inObj, outObj;
                deptId = domObj.dialogs.$deptId.val();
                iary = {
                    data_cate : "HDRS",
                };
                inObj = {
                    trx_id : VAL.T_FBPLSTDAT,
                    action_flg : "Q",
                    iary : [ iary ]
                };
                outObj = comTrxSubSendPostJson(inObj);
                if (outObj.rtn_code === VAL.NORMAL) {
                    var deptIds = domObj.dialogs.$deptId.val();
                    var oary = [];
                    for (var i = 0; i < outObj.oary.length; i++) {
                        var reason = {};
                        reason.dept_id = deptIds;
                        reason.data_ext = outObj.oary[i].data_ext;
                        reason.data_desc = outObj.oary[i].data_desc;
                        oary.push(reason);
                    }
                    setGridInfo(oary,"#modalReasonListGrd");
                }
        },
        holdBtnfun : function (){
            //将按钮的属性变H标志
            domObj.dialogs.$remarkDialog_sureBtn.data("action_flg","H");
            var ids = domObj.grids.$glassListGrd.jqGrid('getGridParam','selarrrow');
            var rowIds = domObj.dialogs.$ReasonListGrd.jqGrid('getDataIDs');
            if(ids.length <= 0){
                showErrorDialog("","请选择需要保留的玻璃！")
                return false;
            }
            if(rowIds.length == 0){
                showErrorDialog("", "当前原因代码信息为空！");
                return false;
            }
             //加载备注的对话框
            domObj.dialogs.$remarkDialog.modal({
                backdrop : true,
                keyboard : false,
                show : false
            });
            domObj.dialogs.$remarkDialog.modal("show");
        },
        //释放
        moveBtnfun : function () {
            //将按钮的属性变R标志
            domObj.dialogs.$remarkDialog_sureBtn.data("action_flg","R");
            var rowId= domObj.grids.$cstHoldListGrd.jqGrid("getGridParam", "selrow");
            var rowData = domObj.grids.$cstHoldListGrd.jqGrid("getRowData", rowId);
            if(!rowData.hasOwnProperty("rsn_code")){
                showErrorDialog("", "请选择一条保留信息");
                return false;
            }
            //加载备注的对话框
            domObj.dialogs.$remarkDialog.modal({
                backdrop : true,
                keyboard : false,
                show : false
            });
            domObj.dialogs.$remarkDialog.modal("show");
        },
        downloadTempFun: function () {
            if ($("#downForm").length > 0) {
                $("#downForm").remove();
            }
            var str = '<form id="downForm" action="download.do" method="post">';
            str = str + '<input type="hidden" name="fileName" id= "fileName" />';
            str = str + "</form>";

            $(str).appendTo("body");
            $("#fileName").val("2400.xlsx");
            $("#downForm").submit();
        }
    }
    var dialogFnc = {
        reasonSureFnc : function() {
            var deptId = domObj.dialogs.$deptId.val();
            if(!deptId){
                showErrorDialog("", "请选择部门代码");
                return false;
            }
            var rowId= domObj.dialogs.$modalReasonListGrd
                .jqGrid("getGridParam", "selrow");
            var rowData = domObj.dialogs.$modalReasonListGrd.jqGrid(
                "getRowData", rowId);
            if(!rowData.hasOwnProperty("data_ext")){
                showErrorDialog("", "请选择一条原因代码");
                return false;
            }
            rowData.dept_id = deptId;
            setGridInfo(rowData, "#ReasonListGrd");
            domObj.dialogs.$addReasonDialog.modal("hide");
        },
        reMarkSureFnc : function() {
            var action_flg = domObj.dialogs.$remarkDialog_sureBtn.data("action_flg");
            var shtOpeMsg = $.trim(domObj.$shtOpeMsg.val());
            if(!shtOpeMsg){
                showErrorDialog("", "备注信息不能为空！");
                return false;
            }
            if(action_flg=='H'){ //保留操作
                var ids = domObj.grids.$glassListGrd.jqGrid('getGridParam','selarrrow');
                var rowIds = domObj.dialogs.$ReasonListGrd.jqGrid('getDataIDs');
                var rowData = domObj.dialogs.$ReasonListGrd.jqGrid("getRowData", rowIds[0]);
                var rsn_dept = rowData.dept_id;
                var rsn_cate = rowData.data_desc;
                var rsn_code = rowData.data_ext;
                var iary = [];
                for(var i = 0 ; i < ids.length ; i++){
                    var rowData = domObj.grids.$glassListGrd.jqGrid("getRowData",ids[i]);
                    var iaryA = {
                        prd_seq_id :rowData.prd_seq_id
                    }
                    iary.push(iaryA);
                }
                var inObj = {
                    trx_id: VAL.T_FSPBOXHLD,
                    action_flg: 'H',
                    iary     : iary,
                    sht_ope_msg : shtOpeMsg,
                    rsn_dept : rsn_dept,
                    rsn_cate : "HOLD",
                    rsn_code : rsn_code,
                    evt_user : VAL.EVT_USER
                };
                var outObj = comTrxSubSendPostJson(inObj);
                if(outObj.rtn_code == VAL.NORMAL){
                    if(crr_query == "Y"){
                        btnFunc.queryBtnfunc();
                    }
                    showSuccessDialog("保留成功");
                    domObj.dialogs.$remarkDialog.modal("hide");
                }
            }else if(action_flg=='R'){ //取消保留操作
                var rowId= domObj.grids.$cstHoldListGrd.jqGrid("getGridParam", "selrow");
                var rowData = domObj.grids.$cstHoldListGrd.jqGrid("getRowData", rowId);
                var evt_seq_id_fk = rowData['evt_seq_id_fk'];
                var rsn_dept = rowData.rsn_dept;
                var rsn_cate = rowData.rsn_cate;
                var rsn_code = rowData.rsn_code;
                var inObj, outObj,
                    inObj = {
                        prd_seq_id  : rowData.prd_seq_id,
                        sht_ope_msg : shtOpeMsg,
                        rsn_dept : rsn_dept,
                        rsn_cate : rsn_cate,
                        rsn_code : rsn_code,
                        evt_seq_id_fk : evt_seq_id_fk,
                        evt_user : VAL.EVT_USER,
                        trx_id: VAL.T_FSPBOXHLD,
                        action_flg: 'M',
                    };
                outObj = comTrxSubSendPostJson(inObj);
                if (outObj.rtn_code == VAL.NORMAL) {
                    btnFunc.queryBtnfunc();
                    showSuccessDialog("释放成功");
                    domObj.dialogs.$remarkDialog.modal("hide");
                }
            }
        }
    }
    // 主页面grid初始化
    var iniGridInfo = function() {
        domObj.grids.$glassListGrd.jqGrid({
            url : "",
            datatype : "local",
            mtype : "POST",
            height : 200,
            width : 425,
            autowidth : true,
            shrinkToFit:false,
            autoScroll: false,
            resizable : true,
            loadonce : true,
            viewrecords : true,
            rownumbers : true,
            rowNum : 20,
            emptyrecords : true,
            multiselect : true,
            pager : domObj.grids.$glassListPg,
            colModel : [ {
                name : 'prd_seq_id',
                index : 'prd_seq_id',
                label : '屏体代码',
                width : 150
            }, {
                name : 'wo_id_fk',
                index : 'wo_id_fk',
                label : '工单代码',
                width : 180
            }, {
                name : 'prd_grade',
                index : 'prd_grade',
                label : '屏体等级',
                width : 180
            }, {
                name : 'prd_stat',
                index : 'prd_stat',
                label : '屏体状态',
                width : 180
            }],
            onSelectRow : function(rowId) {
                var rowData = domObj.grids.$glassListGrd.jqGrid("getRowData", rowId);
                var prd_seq_Id = rowData.prd_seq_id;
                if ("" == prd_seq_Id) {
                    showErrorDialog("", "产品ID不能为空");
                    return false;
                }

                inObjs = {
                    trx_id : VAL.T_FIPINQSHT,
                    action_flg : "Q",
                    prd_seq_id : prd_seq_Id
                };
                outObjs = comTrxSubSendPostJson(inObjs);
                if (outObjs.rtn_code === VAL.NORMAL) {
                    domObj.$prdIdSpan.html(outObjs.prd_seq_id);
                    domObj.$woIdSpan.html(outObjs.wo_id_fk);
                    domObj.$mdlIdSpan.html(outObjs.mdl_id_fk);
                    domObj.$prdStatSpan.html(outObjs.prd_stat);
                    domObj.$pathSpan.html(outObjs.path_id_fk);
                    domObj.$pathVerSpan.html(outObjs.path_ver_fk);
                    domObj.$opeDscSpan.html(globalBean.getOpeDsc(outObjs.ope_id_fk));
                    domObj.$opeNoSpan.html(outObjs.ope_no_fk);
                    domObj.$opeIdSpan.html(outObjs.ope_id_fk);
                    domObj.$opeVerSpan.html(outObjs.ope_ver_fk);
                    domObj.$porcIdSpan.html(outObjs.proc_id_fk);
                }
            },
            onSelectAll: function(aRowids) {
                var rowData = domObj.grids.$glassListGrd.jqGrid("getRowData",  aRowids[0]);
                var prd_seq_Id = rowData.prd_seq_id;
                if ("" == prd_seq_Id) {
                    showErrorDialog("", "产品ID不能为空");
                    return false;
                }
                inObjs = {
                    trx_id : VAL.T_FIPINQSHT,
                    action_flg : "Q",
                    prd_seq_id : prd_seq_Id
                };
                outObjs = comTrxSubSendPostJson(inObjs);
                if (outObjs.rtn_code === VAL.NORMAL) {
                    domObj.$prdIdSpan.html(outObjs.prd_seq_id);
                    domObj.$woIdSpan.html(outObjs.wo_id_fk);
                    domObj.$mdlIdSpan.html(outObjs.mdl_id_fk);
                    domObj.$prdStatSpan.html(outObjs.prd_stat);
                    domObj.$pathSpan.html(outObjs.path_id_fk);
                    domObj.$pathVerSpan.html(outObjs.path_ver_fk);
                    domObj.$opeDscSpan.html(globalBean.getOpeDsc(outObjs.ope_id_fk));
                    domObj.$opeNoSpan.html(outObjs.ope_no_fk);
                    domObj.$opeIdSpan.html(outObjs.ope_id_fk);
                    domObj.$opeVerSpan.html(outObjs.ope_ver_fk);
                    domObj.$porcIdSpan.html(outObjs.proc_id_fk);
                }
            }
        });
        domObj.grids.$glassHoldListGrd.jqGrid({
            url : "",
            datatype : "local",
            mtype : "POST",
            height : 200,
            width : 425,
            autowidth : true,
            shrinkToFit:false,
            autoScroll: false,
            resizable : true,
            loadonce : true,
            viewrecords : true,
            rownumbers : true,
            rowNum : 20,
            emptyrecords : true,
           // multiselect : true,
            pager : domObj.grids.$glassHoldListPg,
            colModel : [ {
                name : 'prd_seq_id',
                index : 'prd_seq_id',
                label : '屏体代码',
                width : 150
            }, {
                name : 'wo_id_fk',
                index : 'wo_id_fk',
                label : '工单代码',
                width : 180
            }, {
                name : 'prd_grade',
                index : 'prd_grade',
                label : '屏体等级',
                width : 180
            }, {
                name : 'prd_stat',
                index : 'prd_stat',
                label : '屏体状态',
                width : 180
            }],
            onSelectRow : function(rowId) {
                var rowData = domObj.grids.$glassHoldListGrd.jqGrid("getRowData", rowId);
                var prd_seq_Id = rowData.prd_seq_id;
                if ("" == prd_seq_Id) {
                    showErrorDialog("", "产品ID不能为空");
                    return false;
                }
                var inObjs = {
                    trx_id : VAL.T_FIPINQSHT,
                    action_flg : "Q",
                    prd_seq_id : prd_seq_Id
                };
                var outObjs = comTrxSubSendPostJson(inObjs);
                if (outObjs.rtn_code === VAL.NORMAL) {
                    domObj.$prdIdSpan.html(outObjs.prd_seq_id);
                    domObj.$woIdSpan.html(outObjs.wo_id_fk);
                    domObj.$mdlIdSpan.html(outObjs.mdl_id_fk);
                    domObj.$prdStatSpan.html(outObjs.prd_stat);
                    domObj.$pathSpan.html(outObjs.path_id_fk);
                    domObj.$pathVerSpan.html(outObjs.path_ver_fk);
                    domObj.$opeDscSpan.html(globalBean.getOpeDsc(outObjs.ope_id_fk));
                    domObj.$opeNoSpan.html(outObjs.ope_no_fk);
                    domObj.$opeIdSpan.html(outObjs.ope_id_fk);
                    domObj.$opeVerSpan.html(outObjs.ope_ver_fk);
                    domObj.$porcIdSpan.html(outObjs.proc_id_fk);
                }
                //选中时初始化Hold信息列表
                btnFunc.iniCstHold(prd_seq_Id);
            }
        });
         domObj.dialogs.$ReasonListGrd.jqGrid({
            url : "",
            datatype : "local",
            mtype : "POST",
            height : 200,
            // width :domObj.dialogs.$modalReasonListDiv.width()*0.99,
            width :  455,
            autowidth : true,
            shrinkToFit:false,
            autoScroll: false,
            resizable : true,
            loadonce : true,
            viewrecords : true,
            rownumbers : true,
            rowNum : 20,
            emptyrecords : true,
            multiselect : false,
            pager : domObj.dialogs.$ReasonListPg,
            colModel : [ {
                name : 'dept_id',
                index : 'dept_id',
                label : '部门代码',
                width : 150
            }, {
                name : 'data_ext',
                index : 'data_ext',
                label : '原因代码',
                width : 180
            }, {
                name : 'data_desc',
                index : 'data_desc',
                label : '原因代码说明',
                width : 170
            } ]
         });
         domObj.grids.$cstHoldListGrd.jqGrid({
            url : "",
            datatype : "local",
            mtype : "POST",
            height : 200,
            // width :domObj.dialogs.$modalReasonListDiv.width()*0.99,
            width :  455,
            autowidth : true,
            shrinkToFit:false,
            autoScroll: false,
            resizable : true,
            loadonce : true,
            viewrecords : true,
            rownumbers : true,
            rowNum : 20,
            emptyrecords : true,
            multiselect : false,
            pager : domObj.grids.$cstHoldListPg,
            colModel : [
                {
                    name : 'prd_seq_id',
                    index : 'prd_seq_id',
                    label : '屏体代码',
                    width : 170,
                    key:true
                },
                {
                    name : 'rsn_dept',
                    index : 'rsn_dept',
                    label : '部门代码',
                    width : 160
                }, {
                    name : 'rsn_code',
                    index : 'rsn_code',
                    label : '原因代码',
                    width : 160
                }, {
                    name : 'rsn_cate',
                    index : 'rsn_cate',
                    label : '原因类型',
                    width : 150
                }, {
                    name : 'evt_seq_id_fk',
                    index : 'evt_seq_id_fk',
                    label : '唯一码',
                    width : 170,
                    key:true
                }, {
                    name : 'evt_usr',
                    index : 'evt_usr',
                    label : '操作人',
                     width : 170
                }, {
                    name : 'evt_timestamp',
                    index : 'evt_timestamp',
                    label : '操作时间',
                    width : 150
            } ]
         });
    }

    var inModelGrid = function() {
        domObj.dialogs.$modalReasonListGrd
            .jqGrid("clearGridData");
        domObj.dialogs.$modalReasonListGrd
            .jqGrid({
                url : "",
                datatype : "local",
                mtype : "POST",
                height : 300,
                // width :domObj.dialogs.$modalReasonListDiv.width()*0.99,
                width : 355,
                autowidth : false,
                shrinkToFit : false,
                resizable : true,
                loadonce : true,
                viewrecords : true,
                rownumbers : true,
                rowNum : 20,
                emptyrecords : true,
                multiselect : false,
                pager : domObj.dialogs.$modalReasonListPg,
                colModel : [ {
                    name : 'dept_id',
                    index : 'dept_id',
                    label : '部门代码',
                    hidden : true,
                    width : 100
                }, {
                    name : 'data_ext',
                    index : 'data_ext',
                    label : '原因代码',
                    width : 150
                }, {
                    name : 'data_desc',
                    index : 'data_desc',
                    label : '原因代码说明',
                    width : 180
                } ],

            });

    };
    var iniButtonAction = function() {
        domObj.buttons.$query_btn.click(function() {
            var prdSeqId = $.trim(domObj.$prdseqIdFk.val());
            var woIdFk   = $.trim(domObj.$woIdFk.val());
            var opeIdFk  = $.trim(domObj.$opeIdFk.val());
            if(prdSeqId){
                btnFunc.queryPrdFunc();
            }else if(woIdFk || opeIdFk){
                btnFunc.queryBtnfunc();
            }else{
                showErrorDialog("", "请选择查询条件");
                return false;
            }
        });
        domObj.buttons.$selectReason_btn.click(function() {
            btnFunc.selectReasonBtnfunc();

        });
        domObj.buttons.$hold_btn.click(function () {
            btnFunc.holdBtnfun();
        });
        domObj.buttons.$release_btn.click(function () {
            btnFunc.moveBtnfun();
        });
        // 确认按钮绑定click事件函数
        domObj.dialogs.$reasonDialog_sureBtn.bind('click',
            dialogFnc.reasonSureFnc);
        domObj.dialogs.$remarkDialog_sureBtn.click(function () {
            dialogFnc.reMarkSureFnc();
        });
        /*  domObj.buttons.$select_file.bind('click',
            select_file);
        domObj.buttons.$upload_btn.change(function() {
            uploadFnc(this);
        });*/

    }
   /* function select_file() {
        document.getElementById("upload_btn").click();
    }*/
    var clearDataAction = function() {
        domObj.$prdIdSpan.html("");
        domObj.$woIdSpan.html("");
        domObj.$mdlIdSpan.html("");
        domObj.$prdStatSpan.html("");
        domObj.$pathSpan.html("");
        domObj.$pathVerSpan.html("");
        domObj.$opeDscSpan.html("");
        domObj.$opeNoSpan.html("");
        domObj.$opeIdSpan.html("");
        domObj.$opeVerSpan.html("");
        domObj.$porcIdSpan.html("");
        domObj.$shtOpeMsg.val("");
        $("#ReasonListGrd").jqGrid('clearGridData');
        $("#glassListGrd").jqGrid('clearGridData');
        $("#modalReasonListGrd").jqGrid('clearGridData');
        $("#cstHoldListGrd").jqGrid('clearGridData');
    }
    var otherActionBind = function(){
        //Stop from auto commit
        $("form").submit(function(){
            return false;
        });

    };
    function uploadFnc(obj) {
        crr_query="N";
        /*
         FileReader共有4种读取方法：
         1.readAsArrayBuffer(file)：将文件读取为ArrayBuffer。
         2.readAsBinaryString(file)：将文件读取为二进制字符串
         3.readAsDataURL(file)：将文件读取为Data URL
         4.readAsText(file, [encoding])：将文件读取为文本，encoding缺省值为'UTF-8'
         */
        var wb;//读取完成的数据
        var rABS = true; //是否将文件读取为二进制字符串
        if(!obj.files) {
            return;
        }
        var fileName = obj.value;
        if(fileName.length > 1 && fileName ) {
            var ldot = fileName.lastIndexOf(".");
            var type = fileName.substring(ldot + 1);
            if(!(type=="xlsx"||type=="xls")) {
                showErrorDialog("", "只能上传excel文件");
                return;
            }
        }
        var f = obj.files[0];
        var reader = new FileReader();
        reader.onload = function(e) {
            var data = e.target.result;
            if(rABS) {
                wb = XLSX.read(btoa(fixdata(data)), {//手动转化
                    type: 'base64'
                });
            } else {
                wb = XLSX.read(data, {
                    type: 'binary'
                });
            }
            //wb.SheetNames[0]是获取Sheets中第一个Sheet的名字
            //wb.Sheets[Sheet名]获取第一个Sheet的数据
            var data = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]);
            var Data= [];
            var inObj,outObj;
            for(var i=0;i<data.length;i++){
                inObj = {
                    trx_id : VAL.T_FIPINQSHT,
                    action_flg : "Q",
                    prd_seq_id : data[i].prd_seq_id
                };
                outObj = comTrxSubSendPostJson(inObj);
                if (outObj.rtn_code === VAL.NORMAL) {
                    // Data[i]=outObj;
                    var dataObj = {
                        prd_seq_id : data[i].prd_seq_id,
                        prd_grade : outObj.prd_grade,
                        prd_qty : outObj.prd_qty,
                        slot_no : outObj.slot_no
                    }
                    Data.push(dataObj);
                }
            }
            domObj.$prdseqIdFk.val("");
            clearDataAction();
            setGridInfo(Data, "#glassListGrd");
        };
        if(rABS) {
            reader.readAsArrayBuffer(f);
        } else {
            reader.readAsBinaryString(f);
        }
        function fixdata(data) { //文件流转BinaryString
            var o = "", l = 0, w = 10240;
            for(; l < data.byteLength / w; ++l) o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w, l * w + w)));
            o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w)));
            return o;
        }
    }
    domObj.$prdseqIdFk.keydown(function(event) {
        if (event.which == 13) {
            btnFunc.queryPrdFunc();
        }
    });
    var compare = function (obj1, obj2) {
        var val1 = obj1.wo_id;
        var val2 = obj2.wo_id;
        if (val1 < val2) {
            return -1;
        } else if (val1 > val2) {
            return 1;
        } else {
            return 0;
        }
    }
    function iniOpeInfo(){
		var inObj, outObj;
		inObj = {
			trx_id : VAL.T_FBPBISOPE,
			action_flg : 'L'
		};
		outObj = comTrxSubSendPostJson(inObj);
		if (outObj.rtn_code == VAL.NORMAL) {
			globalBean.opeObjs = outObj.oary;
		}
	}

    function initFunc() {
        var crr_query="Y";
        domObj.$prdseqIdFk.val("");
        iniGridInfo();
        iniButtonAction();
        initSelectFnc.iniWoIdSel();
        initSelectFnc.iniOpeIdSel();
        inModelGrid();// 初始化dailog中的grids
        otherActionBind();
        clearDataAction();
        iniOpeInfo();
    }
    
    initFunc();
    //enter
 /*   document.onkeydown=function(event){
        var e = event || window.event || arguments.callee.caller.arguments[0];
        if(e && e.keyCode==13){ // 按 enter
            $('.bootbox').modal("hide");
        }
    }*/
    var crr_query="Y";
    //表格自适应
    function resizeFnc(){
        var offsetBottom, divWidth, divWidth1,offsetBottom1,divWidth2,offsetBottom2,divWidth3,offsetBottom3;
        divWidth = $("#middleDiv").width();
        offsetBottom = $(window).height() - $("#middleDiv").offset().top;
        $("#middleDiv").height(offsetBottom * 0.40);
        $("#glassListGrd").setGridWidth(divWidth * 0.95);
        $("#glassListGrd").setGridHeight(offsetBottom * 0.40 - 55);

        divWidth1 = $("#divRight").width();
        offsetBottom1 = $(window).height() - $("#divRight").offset().top;
        $("#divRight").height(offsetBottom1 * 0.40);
        $("#ReasonListGrd").setGridWidth(divWidth1 * 0.95);
        $("#ReasonListGrd").setGridHeight(offsetBottom1 * 0.40 - 55);

        divWidth2 = $("#divRight").width();
        offsetBottom2 = $(window).height() - $("#divRight").offset().top;
        $("#divRight").height(offsetBottom2 * 0.40);
        $("#cstHoldListGrd").setGridWidth(divWidth2 * 0.95);
        $("#cstHoldListGrd").setGridHeight(offsetBottom2 * 0.40 - 55);

        divWidth3 = $("#middleDiv").width();
        offsetBottom3 = $(window).height() - $("#middleDiv").offset().top;
        $("#middleDiv").height(offsetBottom3 * 0.40);
        $("#glassHoldListGrd").setGridWidth(divWidth3 * 0.95);
        $("#glassHoldListGrd").setGridHeight(offsetBottom3 * 0.40 - 55);
    };

    resizeFnc();
    $(window).resize(function() {
        resizeFnc();
    });

});